﻿#region Copyright (c) 2013-04, Olaf Kober <amarok.projects@gmail.com>
//================================================================================
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in
//	all copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//	THE SOFTWARE.
//================================================================================
#endregion

using System;


namespace Amarok.Agents
{
	/// <summary>
	/// This interface represents an in-process message bus that can be used to connect multiple agents. Connected 
	/// agents will receive any message that is published onto the messages bus. Likewise any message published by 
	/// one of the connected agents is automatically published onto the message bus and therefore forwarded to all 
	/// connected agents, including the agent that originally published the message.
	/// </summary>
	public interface IMessageBus :
		ICompletable,
		IAdvertiser,
		IPublisher
	{
		/// <summary>
		/// Connects the supplied agent with the message bus. Messages published by the agent will be forwarded 
		/// to the message bus. Messages published onto the message bus will be forwarded to the agent.
		/// </summary>
		/// 
		/// <param name="agent">
		/// The agent to connect with the message bus.</param>
		/// 
		/// <returns>
		/// An object representing the subscription that can be used to disconnect the agent from the message bus, 
		/// or a null value when connecting the agent with the message bus was not possible since the message bus 
		/// has already been completed.
		/// </returns>
		/// 
		/// <exception cref="ArgumentNullException">
		/// A null reference was passed to a method that did not accept it as a valid argument.</exception>
		ICompletable Connect(IAgent agent);

		/// <summary>
		/// Connects the supplied agent with the message bus. Messages published by the agent will be forwarded 
		/// to the message bus. Messages published onto the message bus will be forwarded to the agent, but only
		/// if the message has either no label or the message has a label equal to the label specified as argument.
		/// </summary>
		/// 
		/// <param name="label">
		/// The label used in this connection. Only messages without label or messages with a label that equals this 
		/// argument will be forwarded to the agent.</param>
		/// <param name="agent">
		/// The agent to connect with the message bus.</param>
		/// 
		/// <returns>
		/// An object representing the subscription that can be used to disconnect the agent from the message bus, 
		/// or a null value when connecting the agent with the message bus was not possible since the message bus 
		/// has already been completed.
		/// </returns>
		/// 
		/// <exception cref="ArgumentNullException">
		/// A null reference was passed to a method that did not accept it as a valid argument.</exception>
		ICompletable Connect(Object label, IAgent agent);

	}
}
